import { Injectable, Injector } from '@angular/core';

import { Router } from "@angular/router";
import { Constant, ServiceResult } from '@core/constant';
import {_HttpClient, SettingsService} from '@delon/theme';
import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
import { mergeMap, catchError } from 'rxjs/operators';
import { Observable } from 'rxjs/Observable';
import { MyHttpClient } from '../MyHttpClient';
import {of} from "rxjs/index";


@Injectable()
export class CommService {
    get cnt(): Constant {
        return this.injector.get(Constant);
    }

    constructor(
      public setting: SettingsService,

      private injector: Injector,
        private http: _HttpClient,
        private myHttp: MyHttpClient
    ) {

    }

    getGoodsUrl(): string {
        return `${this.cnt.baseUrl}/api/file/goods/`;
    }
  genpowq(orderno,conhead) {
    return this.http.post(
      `${this.cnt.baseUrl}/rest/sapEkpoController/getcon/${this.setting.user.username}`,
      conhead,
    );
  }

  genpoAll(orderno,conhead) {
    return this.http.post(
      `${this.cnt.baseUrl}/rest/sapEkpoController/getconall/${this.setting.user.username}`,
      conhead,
    );
  }
  genfhAll(orderno,conhead) {
    return this.http.post(
      `${this.cnt.baseUrl}/rest/sapEkpoFhController/getconall/${this.setting.user.username}`,
      conhead,
    );
  }
  genlfmatnr(orderno,conhead) {
    return this.http.post(
      `${this.cnt.baseUrl}/rest/srmMatnrController/getcon/${this.setting.user.username}`,
      conhead,
    );
  }
  genbl(orderno,conhead) {
    return this.http.post(
      `${this.cnt.baseUrl}/rest/srmBlPlanController/getcon/${this.setting.user.username}`,
      conhead,
    );
  }
  genfh(orderno,conhead) {
    return this.http.post(
      `${this.cnt.baseUrl}/rest/sapEkpoFhController/getvl/${orderno}`,
      conhead,
    );
  }

  genfh105(orderno,conhead) {
    return this.http.post(
      `${this.cnt.baseUrl}/rest/sapEkpoFhController/getvl105/${orderno}`,
      conhead,
    );
  }

  genfh104(orderno,conhead) {
    return this.http.post(
      `${this.cnt.baseUrl}/rest/sapEkpoFhController/getvl104/${orderno}`,
      conhead,
    );
  }

  genbq(orderno,conhead) {
    return this.http.post(
      `${this.cnt.baseUrl}/rest/sapEkpoFhController/getvlbq/${orderno}`,
      conhead,
    );
  }
  genbatchwq(orderno,conhead) {
    return this.http.post(
      `${this.cnt.baseUrl}/rest/sapPoBatchController/getcon/${this.setting.user.username}`,
      conhead,
    );
  }

  genbatchplanwq(orderno,conhead) {
    return this.http.post(
      `${this.cnt.baseUrl}/rest/sapPoBatchController/getconplan/${this.setting.user.username}`,
      conhead,
    );
  }
  getbiUrl(): string {
    return `${this.cnt.baseUrl}/rest/basebi/getbi/`+this.setting.user.username;
  }

  getbi(bitype) {
    return this.http.get(
      `${this.cnt.baseUrl}/rest/basewmbi/getbi/admin`+"?bitype="+bitype,
    );
  }
    getDepartType() {
        return this.getDictValue('org_depart');
    }

    getElementType() {
        return this.getDictValue('authority_element');
    }

    /**
     * 获取菜单类型
     */
    getMenuType() {
        return this.getDictValue('authority_menu');
    }

    /**
     * 获取性别
     */
    getSex() {
        return this.getDictValue('comm_sex');
    }

  /**
   * 获取编号
   */
    getnectno(ordertype){
    this.getno(ordertype).pipe().subscribe(data => {
      const ret: ServiceResult = <ServiceResult> data;
      console.log("1111111111111111111111"+ret['data']);
      return ret['data'];
    })

    }
    getYear() {
        return this.getDictValue('sms_year');
    }

    getSeries() {
        return this.getDictValue('sms_series');
    }

    getProType() {
        return this.getDictValue('sms_pro_type');
    }

    getUserGroup() {
        return this.getDictValue('sms_usergroup');
    }

    getBrand() {
        return this.getDictValue('sms_brand');
    }

    getBrandLine() {
        return this.getDictValue('sms_line');
    }

    getSeasons() {
        return this.getDictValue('sms_prod_season');
    }

    getCategory() {
        return this.getDictValue('sms_category');
    }

    getFrameType() {
        return this.getDictValue('sms_frame_type');
    }

  getno(type: string) {
    return this.http.get(`${this.cnt.baseUrl}/rest/base/getno/${type}`);
  }
  getfileno(type: string) {
    return this.http.get(`${this.cnt.baseUrl}/rest/base/getfileno/${type}`);
  }
    getDictValue(type: string) {
        return this.http.get(`${this.cnt.baseUrl}/rest/base/getDictValue/${type}`);
    }
  getDictentityValue(type: string) {
    return this.http.get(`${this.cnt.baseUrl}/rest/base/getDictentityValue/${type}`);
  }

  getsysusers(syscode: string) {
    return this.http.get(`${this.cnt.baseUrl}/rest/base/getsysuser/${syscode}`);
  }


    getType(type: string) {
    return this.getDictValue(type);
  }
  getentityType(type: string) {
    return this.getDictentityValue(type);
  }
    getCurrencys() {
        return this.getDictValue('sms_user_currency');
    }

    getSiteCodes() {
        return this.getDictValue('sms_user_sitecode');
    }

    getLabels() {
        return this.getDictValue('sms_user_label');
    }
}
